<? session_start();
						
include_once ('core/conn.php');
						
$db = get_conn();
						
check_session();
						
if($_GET['id'] != ''){
							
	$sql = " select * from facilities where id_facility=".$_GET['id']; 
							
	$result = mysql_query($sql);	
							
	if($result){
								
		$row = mysql_fetch_array($result);
		$id_facility = $row['id_facility'];
		$id_ftype = $row['id_ftype'];
		$name = $row['name'];
		$address = $row['address'];
		$address2 = $row['address2'];
							
	}else{
								
		error_handling($sql,mysql_error());
							
	}
						
}
						
						

					
?>
	<html><head>
<script>
					
<!--
						
	function checkdata(obj){
							
		if(obj.id_facility.value ==''){
								
			alert('Please fill the id_facility');
								
			obj.id_facility.focus();
								
			return false;
							
		}
							
		if(isNaN(obj.id_facility.value) ){
								
			alert('id_facility must be a number');
								
			obj.id_facility.focus();
								
			return false;
							
		}				
						
							
		if(obj.id_ftype.value ==''){
								
			alert('Please fill the id_ftype');
								
			obj.id_ftype.focus();
								
			return false;
							
		}
							
		if(isNaN(obj.id_ftype.value) ){
								
			alert('id_ftype must be a number');
								
			obj.id_ftype.focus();
								
			return false;
							
		}				
						
							
		if(obj.name.value ==''){
								
			alert('Please fill the name');
								
			obj.name.focus();
								
			return false;
							
		}
							
		if(obj.address.value ==''){
								
			alert('Please fill the address');
								
			obj.address.focus();
								
			return false;
							
		}
							
		if(obj.address2.value ==''){
								
			alert('Please fill the address2');
								
			obj.address2.focus();
								
			return false;
							
		}
	return true;
						
	}
					
-->
					
</script>
				
</head><body>			
<form name='facilities' method='post' action='/core/facilities.php' onsubmit='return checkdata(this)'>
				
<table width='100%' border='0'>
				  
	<tr>
	  <td valign='top'><a href="facilities_form.php">Crear Nuevo Grupo</a></td>
    </tr>
	<tr>
					
		<td valign='top'> <? 
			
		$sql = "select id_facility as id, f.name as description , ft.name as type_name
					from facilities f, `facility_type` ft
					where f.id_ftype = ft.id_ftype order by description, type_name";
			
		$result = mysql_query($sql);
			
		if($result){
				
			$data ="<table width='50%' align='center'>";
				
			if(mysql_num_rows($result) > 0){
					
				while($row = mysql_fetch_array($result)){
						
					$data .="<tr>
											
						<td align='left' >
							<a href='facilities_form.php?id=".$row['id']."'>".$row['id']."</a>
						</td>

						<td align='left' >
							<a href='facilities_form.php?id=".$row['id']."'>".$row['type_name']." ".$row['description']."</a>
						</td>
									  
						</tr>";
					
				}//while
				
			}//if
				
			else{
					
				$data .= "<tr><td align='center'>No hay facilities registrados</td></tr>";			
				
			}
				
			$data .="</table>";
			
		}else{
				
			error_handling($sql,mysql_error());
			
		}
			
		echo $data;
			
		?>	   &nbsp; </td>
						
	</tr>
					
</table>
</form>
</body></html>